using System;
using System.IO;
using System.Runtime.Serialization;
using System.Xml.Serialization;

namespace mock_ehr_lib.Model
{
    public class ContinuityOfCareRecordSerializer
    {
        private const string DeserializerExceptionMessage = "Error deserializing continuity of care record: {0}";
        
        public ContinuityOfCareRecord Deserialize(string filename)
        {    
            ContinuityOfCareRecord ccr = null;
            try
            {
                using (TextReader reader = new StreamReader(filename))
                {
                    var serializer = new XmlSerializer(typeof(ContinuityOfCareRecord));
                    ccr = serializer.Deserialize(reader) as ContinuityOfCareRecord;
                }
            }catch(Exception exception)
            {
                throw new SerializationException(string.Format(DeserializerExceptionMessage, filename), exception);
            }
            return ccr;
        }
    }
}